package feeinterface.process;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import com.ulwx.tool.NetUtils;
import com.ulwx.tool.StringUtils;
import com.ulwx.type.TObject;

import feeinterface.dao.BaseThirdPartyURLDao;
import feeinterface.modeldb.BaseThirdPartyURL;



/**
 * 获得第三方手机号码的初始化处理程序
 * 
 * @author Administrator
 * 
 */
public class GetPhoneProcessor extends Processor {
	private static Logger log = Logger.getLogger(GetPhoneProcessor.class);

	public void process(HttpServletRequest request,
			Map<String, String[]> parmMap,TObject bodyBytes) throws Exception {
		String var = request.getParameter("var");
		if (StringUtils.hasText(var)) {// 表示为协议005004
			// var=< 005004>_<IMSI>_<MobileID>_< ThirdPartyUrlID >&phone=< Phone
			// >
			//var = var.replace("IMSI_TESt", "IMSI-TEST");
			String[] strs = var.split("_");

			if (strs != null && strs.length == 4) {
				String protocol = strs[0];
				String IMSI = strs[1];
				String ExtVar = strs[2];
				String ThirdPartyUrlID = strs[3];

				BaseThirdPartyURL bu = null;
				try {
					bu = BaseThirdPartyURLDao.findBy(Integer
							.valueOf(ThirdPartyUrlID));
				} catch (Exception ee) {
					log.error("ERROR1,客户端传入的参数非法！", ee);
					throw new Exception("ERROR1,客户端传入的参数非法！"
							+ NetUtils.urlMapToQueryStr(parmMap, "utf-8"));
				}
				String phoneParmName = bu.getPhoneParrmName();
				String Phone = StringUtils.trim(request
						.getParameter(phoneParmName));
				log.debug("Phone=" + Phone);

				parmMap.put("Protocol", new String[] { protocol });
				parmMap.put("IMSI", new String[] { IMSI });
				parmMap.put("ExtVar", new String[] { ExtVar });
				parmMap.put("ThirdPartyUrlID", new String[] { ThirdPartyUrlID });
				parmMap.put("Phone", new String[] { Phone });
				
				//log.debug(""+CollectionUtils.toString(parmMap));


			} else {
				// log.error("ERROR2,客户端传入的参数非法！"+NetUtils.urlMapToQueryStr(map));
				throw new Exception("ERROR2,客户端传入的参数非法！"
						+ NetUtils.urlMapToQueryStr(parmMap));
			}
		}
	}
}
